<?php

use Faker\Factory as Faker;
use App\Models\ChannelUser;
use App\Repositories\ChannelUserRepository;

trait MakeChannelUserTrait
{
    /**
     * Create fake instance of ChannelUser and save it in database
     *
     * @param array $channelUserFields
     * @return ChannelUser
     */
    public function makeChannelUser($channelUserFields = [])
    {
        /** @var ChannelUserRepository $channelUserRepo */
        $channelUserRepo = App::make(ChannelUserRepository::class);
        $theme = $this->fakeChannelUserData($channelUserFields);
        return $channelUserRepo->create($theme);
    }

    /**
     * Get fake instance of ChannelUser
     *
     * @param array $channelUserFields
     * @return ChannelUser
     */
    public function fakeChannelUser($channelUserFields = [])
    {
        return new ChannelUser($this->fakeChannelUserData($channelUserFields));
    }

    /**
     * Get fake data of ChannelUser
     *
     * @param array $postFields
     * @return array
     */
    public function fakeChannelUserData($channelUserFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'channel_id' => $fake->randomDigitNotNull,
            'wechat_user_id' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $channelUserFields);
    }
}
